package com.itheima.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.Book;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.security.krb5.internal.PAData;

import java.util.List;

@RestController
@RequestMapping("/books")
public class bookController {

    @Autowired
    private com.itheima.service.bookService bookService;


    /**
     * 查询全部
     * @return
     */
    @GetMapping
    public List<Book> selectAll(){
        List<Book> list = bookService.list();
        return list;
    }


    /**
     * 新增
     * @param book
     * @return
     */
    @PostMapping
    public boolean save(@RequestBody Book book){
        boolean save = bookService.save(book);
        return save;
    }

    /**
     * 修改
     * @param book
     * @return
     */
    @PostMapping("/update")
    public boolean update(@RequestBody Book book){
        boolean update = bookService.updateById(book);
        return update;
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public boolean delect(@PathVariable Integer id){
        boolean removeById = bookService.removeById(id);
        return removeById;
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/{page}/{size}")
    public Page PagingQuery(@PathVariable Integer page, @PathVariable Integer size){
        Page<Book> BookPage = new Page<>(page, size);
        Page<Book> bookPage = bookService.page(BookPage);
       return bookPage;
    }


}

